package com.lagou.task03;

public class Person implements CallService,InternetService {
    //用户类

    //用户姓名
    String name;

    //用户的手机卡
    SIMCard phoneCard;

    //用户的消费信息
    ConsumptionInfo cInfo;

    public Person(String name, SIMCard phoneCard) {
        this.name = name;
        this.phoneCard = phoneCard;
    }

    //给手机卡充值
    public void recharge(double amt){
        phoneCard.recharge(amt);
        System.out.println("用户进行了充值，当前账户余额" + phoneCard.getCardAccount() + "元");
    }

    //订购套餐
    public void buyMeal(AbstractMeal meal){
        if (phoneCard.getCardAccount() < meal.getMealPrice()){
            System.out.println("余额不足，不能购买该套餐");
            return;
        }

        //消费了金额
        phoneCard.consumption(meal.getMealPrice());

        if (meal instanceof CallService){
            //订购了通话套餐
            CallMeal cMeal = (CallMeal) meal;
            //
            System.out.println("套餐包含" + cMeal.getCallMinute() +"分钟通话时长");
            //增加通话时长
            phoneCard.setCardCallMinute(cMeal.getCallMinute());
        }else if(meal instanceof InternetMeal){
            //订购了上网套餐
            InternetMeal iMeal = (InternetMeal) meal;
            //
            System.out.println("套餐包含" + iMeal.getFlowG() +"G上网流量");
            //增加上网流量
            phoneCard.setInternetFlowG(iMeal.flowG);
        }

        System.out.println("套餐订阅成功，套餐价格" + meal.getMealPrice());
        //记录用户消费金额
        cInfo.setConsumptionAmount(meal.getMealPrice());
        phoneCard.show();
    }


    public void sendMsg(int msgNum){
        System.out.println("用户发了" + msgNum + "条短信");
    }

    @Override
    public void call(int callMinute, SIMCard card) {
        System.out.println("用户准备打电话");
        if (card.getCardCallMinute() < callMinute){
            System.out.println("剩余通话时间还有" + phoneCard.getCardCallMinute() + "，不够用了");
        }else {
            card.setCardCallMinute(0 - callMinute);
            System.out.println("用户成功打了" + callMinute + "分钟电话");
            //记录用户通话时长
            cInfo.setCallMinute(callMinute);
        }
    }

    @Override
    public void surfTheInternet(double flowG, SIMCard card) {
        System.out.println("用户准备上网");
        if (card.getInternetFlowG() < flowG){
            System.out.println("剩余流量还有" + phoneCard.getInternetFlowG() + "G，不够用了");
        }else {
            card.setInternetFlowG(0 - flowG);
            System.out.println("用户成功上网，使用了" + flowG + "G的流量" + "，剩余流量" + card.getInternetFlowG() + "G");
            //记录用户上网流量
            cInfo.setFlowG(flowG);
        }
    }
}
